package logic

import (
	"activity_srv/activity"
	"activity_srv/internal/svc"
	"activity_srv/model"
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type BargainListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBargainListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BargainListLogic {
	return &BargainListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 砍价商品列表
func (l *BargainListLogic) BargainList(in *activity.BargainListRequest) (*activity.BargainListResponse, error) {
	var ba model.Bargain
	list, err := ba.GetBargainList()
	if err != nil {
		pkg.Error("展示失败", zap.Error(err))
		return nil, err
	}
	var baList []*activity.BargainList
	for _, bargain := range list {
		baList = append(baList, &activity.BargainList{
			Name:    bargain.Name,
			SukId:   int64(bargain.SkuId),
			StaTime: bargain.StaTime.Format("2006-01-02 15:04:05"),
			EndTime: bargain.EndTime.Format("2006-01-02 15:04:05"),
			Num:     int64(bargain.Num),
			Price:   int64(bargain.Price),
		})
	}
	return &activity.BargainListResponse{
		List: baList,
	}, nil
}
